package Ar;

import java.util.Arrays;

/**
 * @Author MDD
 * @Description
 * @Version
 * @Date
 **/

//给数组增加长度 并附值

public class AddAr {
    public static void main(String[] args) {
        String[] names = {"小明","小红","小紫"};
        String[] newnames = new String[names.length+1];
        System.arraycopy(names,0,newnames,0,names.length);
//        System.arraycopy(原数组名，起始下标，，起始下新数组名标，复制长度（原数组的长度）);
        for (int i = 0; i < newnames.length; i++) {
            if (newnames[i]==null){
                newnames[i] = "铁子";
                break;//附值一次然后跳出
            }
        }
        System.out.println(Arrays.toString(newnames));


        int[] a = {1,2,3,4,5,6};
        int[] b = {7,8,9};
        int[] c = new int[a.length+b.length];
        System.arraycopy(a,0,c,0,a.length);
        System.arraycopy(b,0,c,a.length,b.length);//数组长度长的在前
        System.out.println(Arrays.toString(c));




    }
}
